package com.neuedu.service.impl;

import com.neuedu.dao.TableDao;
import com.neuedu.dao.UserDao;
import com.neuedu.factory.ClassFactory;
import com.neuedu.service.TableService;

import java.util.List;
import java.util.Map;

public class TableSetServiceImpl implements TableService {
    @Override
    public List<Map<String, Object>> tableSet(Object[] parm) {
        TableDao td = (TableDao) ClassFactory.createObj("TableDao");
        int pageSize = (int) parm[3];
        int pageNum = (int) parm[2];
        String deptnum = (String) parm[0];
        String deptname = (String) parm[1];
        //deptnum和deptname同值
        pageNum = (pageNum - 1) * pageSize;
        if (deptnum == null || deptname.trim().length() == 0 || deptname.equals("undefined")) {
            parm = new Object[]{pageNum, pageSize};
        } else {
            deptnum = "%" + deptnum + "%";
            deptname = "%" + deptname + "%";
            parm = new Object[]{deptnum, deptname, pageNum, pageSize};
        }
        List<Map<String, Object>> list = td.gettable(parm);
        return list;
    }

    @Override
    public int tableDelete(Object[] parm) {
        TableDao td = (TableDao) ClassFactory.createObj("TableDao");
        int flag=td.deleteCol(parm);
        return flag;
    }

    @Override
    public int tableUpdate(Object[] parm) {
        TableDao td = (TableDao) ClassFactory.createObj("TableDao");
        int flag = td.updateCol(parm);
        return flag;
    }

    @Override
    public int getCount(Object[] parm) {
        TableDao td = (TableDao) ClassFactory.createObj("TableDao");
        int count = td.getCount(parm);
        return count;
    }

    @Override
    public int getCount() {
        TableDao td = (TableDao) ClassFactory.createObj("TableDao");
        int count = td.getCount();
        return count;
    }

    @Override
    public List<Map<String, Object>> likeQuery(Object[] objs) {
        TableDao ud = (TableDao) ClassFactory.createObj("TableDao");
        String sql = "SELECT d.id,deptnum,deptname,classifyname,typename FROM deptment d,depttype t,deptclassify c WHERE d.depttypeid=t.id AND deptclassifyid=c.id and (d.deptname like ? OR d.deptnum like ?)";
        return ud.getLikeDept(sql, objs);
    }

}
